<?php
namespace Mall\Controller;

use Common\Controller\ApiController;
use Common\Model\ModelException;
use Util\Tree;

class GoodsAttrController extends ApiController
{
    public function index()
    {
       $input = $this->request();
       $cate_id = filter($input['cate_id'],0);
       $goods = D('Goods')->scope('valid')->where(['cate_id'=>$cate_id])->select();
       $goods_ids = array_column($goods,'goods_id');
       $goods_attrs = D('GoodsAttr')->scope('valid')->where(['goods_id'=>['in',$goods_ids]])->select();
       $goods_attrs = array_group($goods_attrs,'name');
       $list = [];
       foreach($goods_attrs as $attrs=>$val){
       		$list[$attrs] = array_unique(array_column($val,'val'));
       }
      
       $this->response($list);
    }
}
